package _zuoye._04;

import org.dom4j.Document;
import org.dom4j.DocumentException;
import org.dom4j.Element;
import org.dom4j.io.SAXReader;


import java.util.ArrayList;
import java.util.List;


public class Demo04 {
    public static void main(String[] args) throws DocumentException {
        SAXReader reader = new SAXReader();
        Document document = reader.read("Day_14\\src\\_zuoye\\_04\\book.xml");

        Element rool = document.getRootElement();
        List<Element> bookeles = rool.elements("book");
        List<Book> books = new ArrayList<>();
        for (Element ele : bookeles) {
            Book book = new Book();
            book.setCategory(ele.attributeValue("category"));
            book.setTitle(ele.elementTextTrim("title"));
            book.setAuthor(ele.elementTextTrim("author"));
            book.setYear(Integer.parseInt(ele.elementTextTrim("year")));
            book.setPrice(Double.parseDouble(ele.elementTextTrim("price")));
            books.add(book);

        }
        for (Book book : books) {
            System.out.println(book);
        }

    }
}
